package com.umeox.watch.moto.dataservice.mqtt.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.umeox.moto.common.log.Logger;
import com.umeox.moto.common.utils.StringUtils;
import com.umeox.watch.moto.dataservice.mqtt.impl.MqttServiceDelegate;
import com.umeox.watch.moto.dataservice.mqtt.service.MqttService;


public class PingReceiver extends BroadcastReceiver {
    public static final String PING_RECEIVED_INTENT = "com.umeox.intent.action.PING";

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        if (StringUtils.isEmpty(action)) {
            return;
        }
        if (!MqttService.getInstance().isRunning()) {
            Logger.i("Start mqtt service");
            MqttServiceDelegate.startService(context);
        } else {
            Logger.i("MQTT service is running");
        }

        Logger.i("Receive PING, send broadcast ->" + MqttService.MQTT_PING_ACTION);
        context.sendBroadcast(new Intent(MqttService.MQTT_PING_ACTION));
    }
}
